//dofile for evaluating and visualizing model's for college attendance decisions

import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v


//overall attendance
forval i = 1/5{
	gen share_`i' = (s == `i')
}

keep if t == 65
collapse (mean) share_*
gen sim = 1
save "$temp/attendance_all_sim", replace



import delimited "$model/moments/attendance_all.csv", clear 
ren v1 share_1
ren v2 share_2
ren v3 share_3
ren v4 share_4
ren v5 share_5
gen sim = 0


append using "$temp/attendance_all_sim"


lab var share_1 "No Attendance"
lab var share_2 "Public 2-Year"
lab var share_3 "Public 4-Year"
lab var share_4 "Private LQ"
lab var share_5 "Private HQ"
lab def simlab 0 "Data" 1 "Model"
lab val sim simlab

graph bar (asis) share_1 share_2 share_3 share_4 share_5, over(sim) stack percentages ytitle("Percent")
graph export "$output/model_fit_attendance_all.png", replace

*******************Over ability************

clear all
import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v

gen theta_tercile = 1
replace theta_tercile = 2 if theta>0.33 & theta<0.66
replace theta_tercile = 3 if theta>0.66
tab theta_tercile


//overall attendance
forval i = 1/5{
	gen share_`i' = (s == `i')
}

keep if t == 65
collapse (mean) share_*, by(theta_tercile)
gen sim = 1
save "$temp/attendance_ability_sim", replace

import delimited "$model/moments/attendance_ability.csv", clear
ren v1 theta_tercile 
ren v2 share_1 
ren v3 share_2
ren v4 share_3
ren v5 share_4
ren v6 share_5
gen sim = 0

append using "$temp/attendance_ability_sim"

lab var share_1 "No Attendance"
lab var share_2 "Public 2-Year"
lab var share_3 "Public 4-Year"
lab var share_4 "Private LQ"
lab var share_5 "Private HQ"
lab def simlab 0 "Data" 1 "Model"
lab def thetalab 1 "Low Ability" 2 "Medium Ability" 3 "High Ability"
lab val sim simlab
lab val theta_tercile thetalab

graph bar (asis) share_1 share_2 share_3 share_4 share_5, over(sim) over(theta_tercile) stack percentages ytitle("Percent")
graph export "$output/model_fit_attendance_ability.png", replace


********************Over Parent Income Quartile
clear all
import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v

xtile I_quart = I, nq(4)

//overall attendance
forval i = 1/5{
	gen share_`i' = (s == `i')
}

keep if t == 65
collapse (mean) share_*, by(I_quart)
gen sim = 1
save "$temp/attendance_I_quart_sim", replace

import delimited "$model/moments/attendance_inc.csv", clear
ren v1 I_quart 
ren v2 share_1 
ren v3 share_2
ren v4 share_3
ren v5 share_4
ren v6 share_5
gen sim = 0

append using "$temp/attendance_I_quart_sim"

lab var share_1 "No Attendance"
lab var share_2 "Public 2-Year"
lab var share_3 "Public 4-Year"
lab var share_4 "Private LQ"
lab var share_5 "Private HQ"
lab def simlab 0 "Data" 1 "Model"
lab def inclab 1 "Income Q1" 2 "Income Q2" 3 "Income Q3" 4 "Income Q4"
lab val sim simlab
lab val I_quart inclab

graph bar (asis) share_1 share_2 share_3 share_4 share_5, over(sim) over(I_quart) stack percentages ytitle("Percent")
graph export "$output/model_fit_attendance_income.png", replace


********************Over Parent Wealth Quartile
clear all
import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v

xtile W_quart = H, nq(4)

//overall attendance
forval i = 1/5{
	gen share_`i' = (s == `i')
}

keep if t == 65
collapse (mean) share_*, by(W_quart)
gen sim = 1
save "$temp/attendance_W_quart_sim", replace

import delimited "$model/moments/attendance_house.csv", clear
ren v1 W_quart 
ren v2 share_1 
ren v3 share_2
ren v4 share_3
ren v5 share_4
ren v6 share_5
gen sim = 0

append using "$temp/attendance_W_quart_sim"

lab var share_1 "No Attendance"
lab var share_2 "Public 2-Year"
lab var share_3 "Public 4-Year"
lab var share_4 "Private LQ"
lab var share_5 "Private HQ"
lab def simlab 0 "Data" 1 "Model"
lab def wealthlab 1 "Wealth Q1" 2 "Wealth Q2" 3 "Wealth Q3" 4 "Wealth Q4"
lab val sim simlab
lab val W_quart wealthlab

graph bar (asis) share_1 share_2 share_3 share_4 share_5, over(sim) over(W_quart) stack percentages ytitle("Percent")
graph export "$output/model_fit_attendance_wealth.png", replace
graph close












//end of dofile
